package com.shopoo.oauth.domain.entity;

import java.time.LocalDateTime;

import com.shopoo.base.utils.IDUtils;
import com.shopoo.domain.Entity;
import com.shopoo.oauth.domain.constants.IDType;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

/**
 * (OauthUser)实体类
 *
 * @author makejava
 * @since 2021-05-14 17:14:04
 */
@Data
@Entity
public class User {
    /**
     * 用户主键
     */
    private String userId;
    /**
     * 用户名
     */
    private String username;
    /**
     * 用户密码
     */
    private String password;
    /**
     * 昵称
     */
    private String nickname;
    /**
     * 电话号码
     */
    private String phone;
    /**
     * 状态
     */
    private Short status;
    /**
     * 性别 0-女 1-男
     */
    private Short sex;
    /**
     * 创建时间
     */
    private LocalDateTime createTime;

    /**
     * 角色主键
     */
    private Long roleId;
    /**
     * 角色名称
     */
    private String roleName;

    /**
     * 生成用户ID
     * @param 
     * @Return void
     * @Date: 2022/3/17 1:20 PM
     * @Author: <a href="mailto:android_li@sina.cn">MaoYuan.Li</a>
     */ 
    public void generateId() {
        this.userId = IDUtils.getSnowId(IDType.USER_TYPE_ID);
    }

    /**
     * 密码加密
     * @param 
     * @Return void
     * @Date: 2022/3/17 1:20 PM
     * @Author: <a href="mailto:android_li@sina.cn">MaoYuan.Li</a>
     */ 
    public void cryptPassword() {
        if (StringUtils.isBlank(this.password)) {
            return;
        }
        BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder();
        this.password = bCryptPasswordEncoder.encode(this.password);
    }

}
